<?php
class MysqlPlugin extends Yaf_Plugin_Abstract {
    public function routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
    }

    public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
    }


    public function dispatchLoopStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response){
//        $mysql_configs = Yaf_Registry::get("config")->get('product.mysql')->toArray();
        $mysql_configs = array(
            'host' => 'localhost',
            'username' => 'root',
            'password' => 'Sem_1653',
            'dbname' => 'testwhere',
            'charset' => 'utf8'
        );
        $mysql = Yaf_Registry::get('mysql');
        $mysql = '';
        if(empty($mysql_configs))
        {
            throw new Exception('the config of mysql error');
        }

        if(empty($mysql))
        {
            $mysql = Zend_Db::factory('PDO_MYSQL', $mysql_configs);
            Yaf_Registry::set('mysql', $mysql);
        }
    }

    public function preDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
    }

    public function postDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
    }

    public function dispatchLoopShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
    }
}


